package com.java.imauoj.mapper;

import com.java.imauoj.moudel.Role;
import com.java.imauoj.moudel.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {

//    @Select("select user_id,username,nickname,own_sign,via,name,sex,school_id,class_id,in_date,last_date,gitee_username,gitee_token,email,role_id,submit_count,ac_count,exp" +
//            " from user where username=#{user_id}")
//    User getUser(@Param("user_id") int user_id);

    @Select("select user_id,username,nickname,own_sign,via,name,sex,school_id,class_id,in_date,last_date,email,gitee_username,role_id,submit_count,ac_count,poi,exp" +
            " from user ${sql}")
    List<User> getUserList(String sql,String[] list);


    @Update("update user set password=#{password},nickname=#{nickname},own_sign=#{own_sign},via=#{via},name=#{name}," +
            "sex=#{sex},school_id=#{school_id},class_id=#{class_id},in_date=#{in_date},last_date=#{last_date},sgin=#{sgin}," +
            "email=#{email},gitee_username=#{gitee_username},gitee_token=#{gitee_token},role_id=#{role_id},exp=#{exp} where user_id=#{user_id}")
    void updateUser(User user);

    @Insert("insert into user(username,password,nickname,own_sign,via,name,sex,school_id,class_id,sgin,email,role_id)" +
            "values(#{username},#{password},#{nickname},#{own_sign},#{via},#{name},#{sex},#{school_id},#{class_id},#{sgin},#{email},#{role_id})")
    @Options(useGeneratedKeys=true, keyProperty="user_id", keyColumn="id")
    void addUser(User user);

    @Delete("delete user where user_id=#{user_id}")
    void deleteUser(int user_id);

    @Select("select user_id,username,nickname,own_sign,via,name,sex,school_id,class_id,in_date,last_date,gitee_username,gitee_token,email,role_id" +
            " from user where user_id=#{user_id}")
    User getUserOperate(@Param("user_id") int user_id);
}
